<?php

fily_XMLConverter::registerNamespace('textlink', fily_TextLink);
class fily_TextLink extends fily_Control {

    /**
     *
     * @param string $text
     */
    public function __construct($text = '') {
        parent::__construct('a');
        $this->setText($text);
    }

    protected $text;

    /**
     * set the text
     * @param string $text
     */
    public function setText($text) {
        $this->text = $text;
    }

    /**
     * returns the text
     * @return string
     */
    public function getText() {
        return  $this->text ;
    }



    protected function generateHtml() {
        $html = '<' . $this->getTag() . $this->attributes->toString() . ' >'. $this->text .'</'. $this->getTag() .'>';
        return $html;
    }

    /**
     * sets the href attribute
     * @param string $value
     */
    public function setHref($value) {
        $this->attributes->set('href', $value);
    }


    /**
     * gets the href attribute
     * @return string
     */
    public function getHref() {
        return $this->attributes->get('href');
    }

    /**
     * adds an anchor to the href attribute
     * @param string $anchor
     */
    public function addAnchor($anchor) {
        $this->setHref($this->getHref() .'#'.$anchor);
    }

 public function XMLAttributes(array $attributes, $innerValue) {
        $innerValue = trim($innerValue);
        if(!empty($innerValue)) {
            $this->setText($innerValue);
        }
        parent::XMLAttributes($attributes, $innerValue);
    }

}
?>
